package com.daniel.innocence;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.text.format.Time;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceHolder.Callback;

public class seeRecieved {
	public void onReceive(Context context, Intent intent) {
		Bundle extras = intent.getExtras();
		Log.e("TTTTTTTTTTTT", "TTT");
		if (extras != null) {
			String state = extras.getString(TelephonyManager.EXTRA_STATE);
			Log.w("DEBUG", state);
			if (state.equals("android.intent.action.USER_PRESENT")) {
				Camera.PictureCallback mCall = new Camera.PictureCallback()  
				{
		             public void onPictureTaken(byte[] data, Camera camera)  
		             {  
		            	 Bitmap bmp;
		                 //decode the data obtained by the camera into a Bitmap  
		                 bmp = BitmapFactory.decodeByteArray(data, 0, data.length);  
		                 Time now = new Time();
		                 now.setToNow();
		                 //set the iv_image  
		                 String filename = now.toString();
		                 File file = new File(Environment.getExternalStorageDirectory(), filename);
		                 FileOutputStream fos;
		                 byte[] dataTwo = bmp.toString().getBytes();
		                 try {
		                     fos = new FileOutputStream(file);
		                     fos.write(dataTwo);
		                     fos.flush();
		                     fos.close();
		                 } catch (FileNotFoundException e) {
		                     // handle exception
		                 } catch (IOException e) {
		                     // handle exception
		                 }

		             }  
		         };  
			}
		}
	}   
}
